home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freaks Macintosh Archive
/
Freaks Macintosh Archive.bin
/
Freaks Macintosh Archives
/
Internet
/
tcpreroute1.3d.sit
/
tcp_reroute_sethost.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-27
|
2KB
|
91 lines
/* TCP ReRoute - Set Host (for linux)
*
* This is the Set Host program for the TCP ReRouter.
* -Seti
* To compile: gcc tcp_reroute_sethost.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/time.h>
main(int argc, char *argv[])
{
int fd;
int sin_size;
int bytes, i;
char data[100];
char new_data[100]="";
char new_host[50];
char new_port[6];
struct sockaddr_in dest_addr;
struct hostent *he;
if(argc != 2) {
printf("Usage: %s host\n", argv[0]);
return -1;
}
if ((he=gethostbyname(argv[1])) == NULL) { /* get the host info */
printf("Error: Unknown host.\n");
return -1;
}
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(3627);
dest_addr.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(dest_addr.sin_zero), 8);
if((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
printf("Error: Could not open socket");
return -1;
}
if(connect(fd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == -1) {
printf("Error: Could not connect to socket.\n");
return -1;
}
send(fd, "set_RTH_here", 12, 0);
bytes = recv(fd, data, 50, 0);
data[bytes] = '\0';
printf("The current host is: ");
for(i=20; i<bytes; i++)
printf("%c", data[i]);
printf("\nChange the destination host: ");
scanf("%s", &new_host);
printf("Change the destination port: ");
scanf("%s", &new_port);
strcat(new_data, "set_remote_telnet_host:");
strcat(new_data, new_host);
strcat(new_data, ":");
strcat(new_data, new_port);
send(fd, new_data, strlen(new_data), 0);
bytes = recv(fd, data, 9, 0);
data[bytes] = '\0';
printf("%s\n---", &data);
printf("\nDestination host: %s", &new_host);
printf("\nDestination port: %s", &new_port);
printf("\nTCP ReRouter will listen on port %s for connections.\n", &new_port);
//Let server kill the connection...
return 0;
}